package com.gp.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gp.dao.TbCarCommentDao;
import com.gp.entity.CarComment;
import com.gp.entity.TbCar;
import com.gp.service.CarCommentService;
import com.gp.util.CommonResult;
import com.gp.vo.CarCommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class CarCommentServiceImpl implements CarCommentService {

    @Resource
    private TbCarCommentDao tbCarCommentDao;

    @Override
    public CommonResult findAll(Integer page, Integer limit, CarCommentVo carCommentVo) {
        PageHelper.startPage(page, limit);
        List<CarComment> list = tbCarCommentDao.selectByPage(carCommentVo.getUsername(), carCommentVo.getCarname());
        PageInfo<CarComment> pageInfo = new PageInfo<>(list);
        return new CommonResult(200, "查询成功", pageInfo);
    }

    @Override
    public CommonResult deleteById(Integer id) {
        int i = tbCarCommentDao.deleteById(id);
        if (i > 0) {
            return new CommonResult(200, "删除成功", null);
        } else {
            return new CommonResult(500, "删除失败", null);
        }
    }
}
